package com.tarena.lbs.marketing.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.marketing.web.service.CouponUserService;
import com.tarena.lbs.pojo.marketing.param.UserCouponsParam;
import com.tarena.lbs.pojo.marketing.query.UserCouponCodeQuery;
import com.tarena.lbs.pojo.marketing.query.UserCouponQuery;
import com.tarena.lbs.pojo.marketing.vo.UserCouponsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CouponUserController {
    @Autowired
    private CouponUserService couponUserService;
    @PostMapping("/marketing/user/receive/list")
    public Result<PageResult<UserCouponsVO>> userCouponsList(
            @RequestBody UserCouponQuery query)
            throws BusinessException {
        PageResult<UserCouponsVO> voPages=couponUserService.userCouponsPage(query);
        return new Result<>(voPages);
    }
    @PostMapping("/marketing/user/receive/detail")
    public Result<UserCouponsVO> userCouponsDetail(@RequestBody UserCouponCodeQuery query)
        throws BusinessException {
        UserCouponsVO vo=couponUserService.userCouponsDetail(query);
        return new Result<>(vo);
    }

    //用户领取单张优惠券
    @PostMapping("/marketing/user/receive/save")
    public Result<Void> userCouponsSave(@RequestBody UserCouponsParam param)
        throws BusinessException{
        couponUserService.userCouponsSave(param);
        return Result.success();
    }
}
